package com.party.core.service.mall.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.common.utils.UUIDUtils;
import com.party.core.dao.read.mall.MallGoodsCategoryReadDao;
import com.party.core.dao.write.mall.MallGoodsCategoryWriteDao;
import com.party.core.model.mall.MallGoodsCategory;
import com.party.core.service.mall.IMallGoodsCategoryService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * 商品分类关系表
 * Created by yifeng
 *
 * @date 2018/3/28 0028
 * @time 下午 15:55
 */
@Service
public class MallGoodsCategoryService implements IMallGoodsCategoryService {
    @Autowired
    private MallGoodsCategoryReadDao mallGoodsCategoryReadDao;

    @Autowired
    private MallGoodsCategoryWriteDao mallGoodsCategoryWriteDao;

    @Override
    public String insert(MallGoodsCategory mallGoodsCategory) {
        mallGoodsCategory.setId(UUIDUtils.generateRandomUUID());
        boolean result = mallGoodsCategoryWriteDao.insert(mallGoodsCategory);
        if (result) {
            return mallGoodsCategory.getId();
        }
        return null;
    }

    @Override
    public boolean update(MallGoodsCategory mallGoodsCategory) {
        return mallGoodsCategoryWriteDao.update(mallGoodsCategory);
    }

    @Override
    public boolean deleteLogic(String id) {
        return false;
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return mallGoodsCategoryWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        return false;
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return mallGoodsCategoryWriteDao.batchDelete(ids);
    }

    @Override
    public MallGoodsCategory get(String id) {
        return mallGoodsCategoryReadDao.get(id);
    }

    @Override
    public List<MallGoodsCategory> listPage(MallGoodsCategory mallGoodsCategory, Page page) {
        return mallGoodsCategoryReadDao.listPage(mallGoodsCategory, page);
    }

    @Override
    public List<MallGoodsCategory> list(MallGoodsCategory mallGoodsCategory) {
        return mallGoodsCategoryReadDao.listPage(mallGoodsCategory, null);
    }

    @Override
    public List<MallGoodsCategory> batchList(Set<String> ids, MallGoodsCategory mallGoodsCategory, Page page) {
        return null;
    }

    @Override
    public MallGoodsCategory getUnique(MallGoodsCategory category) {
        return mallGoodsCategoryReadDao.getUnique(category);
    }

    @Override
    public void deleteByUnique(MallGoodsCategory category) {
        mallGoodsCategoryWriteDao.deleteByUnique(category);
    }

    @Override
    public List<MallGoodsCategory> findByGoodsId(String goodsId) {
        MallGoodsCategory category = new MallGoodsCategory();
        category.setGoodsId(goodsId);
        return mallGoodsCategoryReadDao.listPage(category, null);
    }

    @Override
    public List<MallGoodsCategory> findByCategoryId(String categoryId) {
        MallGoodsCategory category = new MallGoodsCategory();
        category.setCategoryId(categoryId);
        return mallGoodsCategoryReadDao.listPage(category, null);
    }
}
